import 'package:flame/components.dart';
import 'package:flame/events.dart';
import 'package:flutter_flame/component/SpriteEntity.dart';
import 'package:flutter_flame/config/AssetsName.dart';
import 'package:flutter_flame/config/GameConfig.dart';

import '../../GameWorld.dart';

class ShovelComponent extends PositionComponent with GameConfig {
  final Vector2 initPos = Vector2(565, 1);

  @override
  Future<void> onLoad() async {
    addAll([ShovelBank(), Shovel(initPosition: initPos)]);
    position = initPos;
    priority = shovelPriority;
  }
}

class Shovel extends SpriteEntity
    with TapCallbacks, HasWorldReference<GameWorld>, DragCallbacks {
  Shovel({required this.initPosition}) : super(AssetsName.shovel);
  late Sprite shovel;
  late Vector2 initPosition;

  @override
  Future<void> onLoad() async {
    await super.onLoad();
    setSize(90.0);
    position = Vector2(0, 0);
    shovel = await Sprite.load(AssetsName.shovelHiRes);
  }

  @override
  void onTapDown(TapDownEvent event) {
    world.operateShove(shovel, initPosition);
    super.onTapDown(event);
  }
}

class ShovelBank extends SpriteEntity {
  ShovelBank() : super(AssetsName.shovelBank);

  @override
  Future<void> onLoad() async {
    await super.onLoad();
    setSize(90.0);
    position = Vector2(0, 0);
  }
}
